package com.probiz.estore.common.model.content;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.probiz.estore.common.model.content.base.ContentTbl;
import com.probiz.estore.core.util.ContextUtil;
import com.probiz.estore.other.service.TagManager;

/**
 * Model - Business object
 * This file won't get overwritten.
 * 文章
 */
public class Content extends ContentTbl {
    public static final int STATE_INVALID = 0; //非激活
    public final static Short STATUS_PUBLISHED = 1; //发布中
    public final static Short STATUS_WAITING_FOR_PUBLISH = 2; //等待发布
    public final static Short STATUS_INACTIVE = 0; //退出发布

    public final static Short VALID_PERIOD_NEVERINVALID = (short) 0;//永不过期

    public final static Map<Short, Integer> validPeriodMap = new HashMap<Short, Integer>();

    static {
        validPeriodMap.put((short) 0, -1);//永不过期
        validPeriodMap.put((short) 1, 7);//7天
        validPeriodMap.put((short) 2, 15);//15天
        validPeriodMap.put((short) 3, 30);//30天
        validPeriodMap.put((short) 4, 60);//60天
        validPeriodMap.put((short) 5, 90);//90天
        validPeriodMap.put((short) 6, 180);//180天
    }

    /**
     * Default Empty Constructor for class Content
     */
    public Content() {
        super();
    }

    /**
     * Default Key Fields Constructor for class Content
     *
     * @param in_contentId 文章id
     */
    public Content(Integer in_contentId) {
        super(in_contentId);
    }

    /**
     * 定义实体的业务名取值
     *
     * @return 业务名
     */
    public String getContentName() {
        return this.contentTitle;
    }
    
    public List<ContentMedia> getContentImages(){
    	List<ContentMedia> contentImages = new ArrayList<ContentMedia>();
    	for(ContentMedia contentMedia: contentMedias){
    		if(contentMedia.getMediaType().equals(ContentMedia.TYPE_IMAGE)){
    			contentImages.add(contentMedia);
    		}
    	}
    	return contentImages;
    }
    
    /**
     * 获得标签名称
     * @return
     */
    public String getTagNames(){
    	TagManager tagManager = (TagManager) ContextUtil.getSpringBeanById("tagManager");
    	return tagManager.getTagNames(this);
    }
    /**
     * 获得标签数组
     * @return
     */
    public String[] getTagNameArray(){
    	TagManager tagManager = (TagManager) ContextUtil.getSpringBeanById("tagManager");
    	return tagManager.getTagNameArray(this);
    }


}
